<?php
require_once 'model/Model.php';
class ModelEvent extends Model{
    
    function __construct() {
        parent::connection();
    }
    
    //retourne un tableau mysql_fetch_array 
    function selectAll(){
        $query = "select * from sb_event ORDER BY EVENT_TIME DESC";
        $result = mysql_query($query);
        return $result;        
    }
    
    function update($id, $title, $content, $date, $hour){
        $query = "update sb_event set EVENT_TITLE='$title', EVENT_CONTENT='$content', EVENT_TIME = '$date', EVENT_HOUR='$hour' where EVENT_ID=$id";
        $result = mysql_query($query);
    }
    
    function insert(){
        $query = "insert into sb_event (EVENT_TITLE, EVENT_CONTENT) values ('default title', 'default content')";
        mysql_query($query);
        return mysql_insert_id();
    }
    
    function delete($id){
        $query = "delete from sb_event where EVENT_ID=$id";
        mysql_query($query);       
    }
    
    function exist($id){
        $query = "select * from sb_event where EVENT_ID='$id' LIMIT 1";
        $result = mysql_query($query);
        if(mysql_num_rows($result)==1){
            return $result;
        }
        return "empty";
    }
    
    function addImg($id, $img){
        $query = "update sb_event set EVENT_IMG='$img' where EVENT_ID=$id";
        $result = mysql_query($query);  
    }
    
}
?>
